package com.rrd.itext.html;

import com.itextpdf.text.Chunk;
import com.itextpdf.text.Element;
import com.itextpdf.text.FontProvider;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.tool.xml.Tag;
import com.itextpdf.tool.xml.css.apply.MarginMemory;
import com.itextpdf.tool.xml.css.apply.PageSizeContainable;
import com.itextpdf.tool.xml.html.CssAppliers;
import com.itextpdf.tool.xml.html.CssAppliersImpl;
import com.itextpdf.tool.xml.pipeline.html.ImageProvider;

public class ITextServiceCssAppliers extends CssAppliersImpl{
    private ITextServiceChunkCssApplier chunk;
    private ITextServiceChunkCssApplier chunkcopy;
    private ITextServiceParagraphCssApplier paragraph;
    private ITextServicePdfPTableCssApplier pdfPTable;
    public ITextServiceCssAppliers() {
        super();
        chunk = new ITextServiceChunkCssApplier();
        chunkcopy = new ITextServiceChunkCssApplier();
        paragraph = new ITextServiceParagraphCssApplier(this);
        pdfPTable = new ITextServicePdfPTableCssApplier();
    }

    public ITextServiceCssAppliers(FontProvider fontProvider) {
        super(fontProvider);
        chunk = new ITextServiceChunkCssApplier();
        chunk.setFontProvider(fontProvider);
        chunkcopy = new ITextServiceChunkCssApplier();
        paragraph = new ITextServiceParagraphCssApplier(this);
        pdfPTable = new ITextServicePdfPTableCssApplier();
    }

    
    
    @Override
    public Element apply(Element e, final Tag t, final MarginMemory mm, final PageSizeContainable psc, final ImageProvider ip) {
        if (e instanceof Chunk) {
            e = chunk.apply((Chunk) e, t);
        } else if (e instanceof Paragraph) {
            e = paragraph.apply((Paragraph) e, t, mm);
        } else if (e instanceof PdfPTable) {
            e = pdfPTable.apply((PdfPTable) e, t, mm);
        } else {
            e = super.apply(e, t, mm, psc, ip);
        }
        return e;
    }
    

    public ITextServiceChunkCssApplier getChunkCssAplier() {
        return  this.chunkcopy;
    }

    public void setChunkCssAplier(final ITextServiceChunkCssApplier chunkCssAplier) {
        this.chunkcopy = chunkCssAplier;
    }

    public CssAppliers clone() {
        ITextServiceCssAppliers clone = new ITextServiceCssAppliers();
        clone.chunk = chunk;
        clone.paragraph = paragraph;
        return clone;
    }
}
